class rectangle { private int length,breadth; public void area() { int a=length*breadth; System.out.println("Area is "+a); } public rectangle(int m,int n) { length=m; breadth=n; } } class demo { public static void main(String args[]) { rectangle a=new rectangle(5,7); a.area(); } }
Area is 35
class Account { private int accno,balance; public Account(int an,int bl) { accno = an; balance = bl; } public void showData() { System.out.println("AccNo is"+accno); System.out.println("Balance is"+ balance); } public void deposit(int amt) { balance=balance+amt; } public void withdraw(int amt) { balance=balance-amt; } } class demo { public static void main(String args[]) { Account a=new Account(4117,25000); a.showData(); a.deposit(7000); a.withdraw(2000); a.deposit(4000); a.showData(); } }
AccNo is 4117 Balance is 25000 AccNo is 4117 Balance is 34000
class Account { private int accno; private double balance; public Account(int an,int bl) { accno = an; balance = bl; } public void showData() { System.out.println("AccNo is"+ accno); System.out.println("Balance is"+balance); } public void addInterest(double r,int n) { double si=balance*r*n/100; balance =balance+si; } } class demo { public static void main(String args[]) { Account a = new Account(4117,25000); a.showData(); a.addInterest(10.25,3); a.showData(); } }
AccNo is 4117 Balance is 25000 AccNo is 4117 Balance is 32687.5
class Worker { private int wages,wdays; public Worker(int w,int d) { wages=w; wdays=d; } public void payment() { int p=wages*wdays; System.out.println("Payment is"+p); } public void addWdays(int n) { wdays=wdays+n; } } class demo { public static void main(String args[]) { Worker a; a = new Worker(500,5); a.payment(); a.addWdays(2); a.payment(); a.addWdays(3); a.payment(); } }
Payment is 2500 Payment is 3500 Payment is 5000